package com.ruoyi.lhky.controller;

import com.ruoyi.lhky.pojo.V0;
import com.ruoyi.lhky.service.V0Service;
import com.ruoyi.lhky.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v0")
@Tag(name = "V0管理", description = "V0表的相关操作")
public class V0Controller {

    @Autowired
    private V0Service v0Service;

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "新增V0记录", description = "新增V0记录")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "新增成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R saveOrUpdateV0Data(@RequestBody V0 v0) {
        return v0Service.saveOrUpdateV0Data(v0);
    }

    @PostMapping("/updateGroup")
    @Operation(summary = "修改受试者入组记录", description = "修改受试者入组记录")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "新增成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    private R updateTesterGroup(@RequestParam Long testerId, @RequestParam int randomResult){
        System.out.println(testerId + " " + randomResult);
        return v0Service.updateTesterGroup(testerId, randomResult);
    }

    @GetMapping("/getByTesterId")
    @Operation(summary = "根据testerId获取研究结束记录", description = "获取指定testerId的研究结束记录")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "400", description = "请求参数错误"),
            @ApiResponse(responseCode = "404", description = "记录不存在"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    public R getV0ByTesterId(@RequestParam Long testerId) {
//        System.out.println(v0Service.getV0ByTesterId(testerId));
        if (!(v0Service.getV0ByTesterId(testerId) == null)){
            return new R(true, v0Service.getV0ByTesterId(testerId));
        }else return new R(false,"数据未找到");
    }
}
